<template>
	<view class="container">
		<view class="yy-detail-con">
			<view class="yy-detail-con-t">
				<view class="yy-detail-con-tText">
					<text>就诊人</text>
					<text v-if="patientName == ''">请添加就诊人</text>
					<text v-else>{{patientName}}</text>
				</view>
				<view class="yy-detail-con-tImg" @click="choose(patientId)">
					<image src="../../static/icon_right_white.png" mode="widthFix"></image>
				</view>
			</view>
			<view class="yy-detail-con-des">
				<view class="yy-detail-con-desItem">
					<text>就诊医院</text>
					<text>{{docinfo.hospital_name}}</text>
				</view>
				<view class="yy-detail-con-desItem">
					<text>就诊科室</text>
					<text>{{docinfo.department_name}}</text>
				</view>
				<view class="yy-detail-con-desItem">
					<text>就诊医生</text>
					<text>{{docinfo.nickname}}</text>
				</view>
				<view class="yy-detail-con-desItem">
					<text>就诊时间</text>
					<text class="yy-detail-con-Sshow">{{year}} {{time}}</text>
				</view>
			</view>
		</view>
		<view class="yy-detail-btn">
			<view class="yy-detail-btnNav" @click="submit">提交</view>
		</view>
		<view class="pagedes" v-show="officedes === 0">
			<view class="pagedesnav">
				<view class="pagedesSub">
					<view class="pagedesSub-top">
						<view class="pagedesSub-topImg">
							<image src="../../static/ic_wateing.png" mode="widthFix"></image>
						</view>
						<view class="pagedesSub-topTitle">
							<text>无法预约</text>
						</view>
						<view class="pagedesSub-topreson">已爽约超过三次，当前无法预约 您可在{{ordertime}}开始预约</view>
					</view>
					<view class="pagedesSub-bottom" @click="hidoffice">关闭</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import app from '../../App.vue'
	export default{
		data(){
			return{
				officedes:1,
				docId:'',		//医生id
				time:'',		//上午下午
				month:'',		//月日
				year:'',		//年月日
				docinfo:'',		//医生信息
				// patient:'',		//就诊人信息
				patientName:'',	//就诊人姓名
				patientId:'',	//就诊人id
				paibanId:'',	//排版id
				// reson:'',		//失败原因
				ordertime:'',
			}
		},
		onLoad(options) {
			this.docId = options.docId
			this.time = options.time
			this.month = options.month
			this.year = options.year
			this.paibanId = options.paibanId
			this.getpatientlist()
			// uni.getSystemInfoSync({
			// 	success(res=>{
			// 		if(res.platform === 'ios'){
						
			// 		}
			// 	})
			// })
		},
		onShow() {
			// if(this.patinentId == ''){
			// 	this.getpatientlist()
			// }else{
			// 	this.getpatetdetail()
			// }
			this.getinfo()
		},
		methods:{
			hidoffice(){
				this.officedes = 0
				uni.showLoading({
					title:'加载中',
					success() {
						setTimeout(function(){
							uni.hideLoading()
							uni.navigateTo({
								url:'/pages/index/index'
							})
						},1300)
					}
				})
			},
			getinfo(){						//医生信息
				let that = this,
				data = {
					user_id:that.docId
				}
				app.post('api/order/confirmOrder',data).then(res=>{
					if(res.code == 1){
						that.docinfo = res.data
					}else if(res.code == 0){
						uni.showToast({
							title: res.msg,
							icon: 'none',
							mask: true
						})
					}else if(res.code == 401){
						uni.showToast({
							title: res.msg,
							icon: 'none',
							mask: true
						})
					}
				}).catch(err=>{
					uni.showToast({
						title: res.msg,
						icon: 'none',
						mask: true
					})
				})
			},
			// getpatetdetail(){				//就诊人详情
			// 	let that = this,
			// 	data={
			// 		user_member_id:that.patinentId
			// 	}
			// 	app.post('api/user_member/getUserMemberInfo',data).then(res=>{
			// 		if(res.code == 1){
			// 			console.log(res)
			// 			that.patientName = res.data.name
			// 			that.patientId = res.data.id
			// 			// that.patient = res.data
			// 		}
			// 	})
			// },
			getpatientlist(){				//就诊人列表
				let that = this,
				data={}
				app.post('api/user_member/getUserMemberList',data).then(res=>{
					if(res.code == 1){
						that.patientName = res.data[0].name
						that.patientId = res.data[0].id
						console.log(res.data[0])
					}
				})
			},
			choose(id){					//选择就诊人
				uni.showLoading({
					title:'加载中',
					success() {
						setTimeout(function(){
							uni.hideLoading()
							uni.navigateTo({
								url:'/pages/yuyue/patient?patientId='+id
							})
						},1300)
					}
				})
			},
			submit(){					//提交
				let that = this,
				data = {
					user_scheduling_id:that.paibanId,
					user_member_id:that.patientId,
					user_id:that.docId,
					date:that.year
				}
				app.post('api/order/createOrder',data).then(res=>{
					if(res.code == 1){
						let order_id = res.data.order_id
						uni.showLoading({
							title:'加载中',
							success() {
								setTimeout(function(){
									uni.hideLoading()
									uni.reLaunch({
										url:'/pages/yuyue/success?order_id='+order_id
									})
								},1300)
							}
						})
					}else if(res.code == 401){
						uni.showToast({
							title: res.msg,
							icon: 'none',
							mask: true
						})
					}else if(res.code === -1){
						that.ordertime = res.data
						this.officedes = 0
					}
				}).catch(err=>{
					uni.showToast({
						title: err.msg,
						icon: 'none',
						mask: true
					})
				})
			}
		}
	}
</script>

<style>
	@import url("../../common/yuyuedetail.css");
</style>
